package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划",description = "护理计划相关接口")
public class NursingPlanController extends BaseController{

    @Autowired
    private NursingPlanService nursingPlanService;


    /**
     * 查询所有护理计划
     */
    @ApiOperation(value = "查询所有护理计划",notes = "返回所有护理计划信息")
    @GetMapping
    public ResponseResult<List<NursingPlanVo>> selectAll() {
        return success(nursingPlanService.selectAll());
    }


    /**
     * 条件分页查询
     */
    @ApiOperation(value = "条件分页查询",notes = "返回条件分页查询结果")
    @GetMapping("/search")
    public ResponseResult<PageResponse<NursingPlanVo>> selectByPage(
            @ApiParam(value = "页码",required = true) Integer pageNum,
            @ApiParam(value = "每页显示的记录数，用于控制每页包含的护理计划数量",required = true) Integer pageSize,
            @ApiParam(value = "护理计划名称") String name,
            @ApiParam(value = "护理计划状态") Integer status) {
        return success(nursingPlanService.selectByPage(pageNum,pageSize,name,status));
    }


    /**
     * 新增护理计划
     */

    @ApiOperation(value = "新增护理计划",notes = "传入护理计划信息，返回新增结果")
    @PostMapping
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        return toAjax(nursingPlanService.addNursingPlan(nursingPlanDto));
    }


    /**
     * 根据id查询护理计划信息
     */
    @ApiOperation(value = "根据id查询护理计划信息",notes = "传入护理计划id，返回护理计划信息")
    @GetMapping("/{id}")
    public ResponseResult<NursingPlanVo> selectById(@PathVariable Long id) {
        return success(nursingPlanService.selectById(id));
    }


    /**
     * 根据id编辑护理计划信息
     */
    @ApiOperation(value = "根据id编辑护理计划信息",notes = "传入护理计划信息，返回编辑结果")
    @PutMapping("/{id}")
    public ResponseResult updateNursingPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        return toAjax(nursingPlanService.updateNursingPlan(nursingPlanDto));
    }


    /**
     * 根据id删除护理计划
     */
    @ApiOperation(value = "根据id删除护理计划",notes = "传入护理计划id，返回删除结果")
    @DeleteMapping("/{id}")
    public ResponseResult deleteNursingPlan(@PathVariable Long id) {
        return toAjax(nursingPlanService.deleteById(id));
    }

    /**
     * 启用禁用护理计划
     */
    @ApiOperation(value = "启用禁用护理计划",notes = "传入护理计划id和状态，返回更新结果")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateNursingPlanStatus(@PathVariable Long id,@PathVariable Integer status) {
        return toAjax(nursingPlanService.updateNursingPlanStatus(id,status));
    }

}
